<?php

class RegisterView {
	
	/**
	 * Static string kyes for register form.
	 * @var String
	 */
	private static $USERNAME 		= "username";
	private static $PASSWORD	 	= "passwordOne";
	private static $PASSWORDREPEAT	= "passwordTwo";
	private static $REGISTERBUTTON 	= "registerButtonID";
	private static $DOREGISTER		= "doRegister";
	
	/**
	 * Messages for register feedback.
	 * @var String
	 */
	private $message;
	
	/**
	 * @var NavigationView
	 */
	private $navView;
	
	/**
	 * @param NavigationView $navView
	 */
	public function __construct(NavigationView $navView) {
		$this->navView = $navView;
	}
	
	public function getRegisterUserContent() {
		return "<form action='?". $this->navView->getRegisterURL() ."&". self::$DOREGISTER ."' method='post' enctype='multipart/form-data'>
					<fieldset>
						$this->message
						<legend>Register new user - Write username and password</legend>
						<label for='" . self::$USERNAME . "' >Username :</label>
						<input type='text' size='20' name='" . self::$USERNAME . "' id='UserNameID' value='" . $this->getUsername() . "' />
						<label for='" . self::$PASSWORD . "' >Password :</label>
						<input type='password' size='20' name='" . self::$PASSWORD . "' id='PasswordID' />
						<label for='" . self::$REGISTERBUTTON . "' >Skicka :</label>
						<input type='submit' name='' id='" . self::$REGISTERBUTTON . "'  value='Register' />
					</fieldset>
				</form>";
	}
	
	/**
	 * @return boolean
	 */
	public function isRegisteringUser() {
		return isset($_GET[self::$DOREGISTER]);
	}
	
	public function registerOk() {
		header("Location: index.php?".$this->navView->getUserWasRegisteredURL()."=".$this->getUsername()."");
	}
	
	/**
	 * @param string $e
	 */
	public function setMessage($e) {
		$this->message = "<p class='ErrorMessage'>$e</p>";
	}
	
	/**
	 * @return String
	 */
	public function getUsername() {
		if (isset($_POST[self::$USERNAME])) {
			return strip_tags($_POST[self::$USERNAME]);	
		}
		else
			return "";
	}
	
	/**
	 * @return String
	 */
	public function getPassword() {
		if (isset($_POST[self::$PASSWORD]))
			return strip_tags($_POST[self::$PASSWORD]);
		else
			return "";
	}
}